package com.jolink.omiis.wechat.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期处理
 * 
 * @author WangYanqing
 *
 */
public class DateUtil {

	public static String getCurrentTimeMillis() {
		return String.valueOf(System.currentTimeMillis());
	}

	private static String defaultFormat = "yyyy-MM-dd HH:mm:ss";

	public static Date parseDate(String str) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat(defaultFormat);
		return sdf.parse(str);
	}

	public static String getCurrentDate() {
		return formatDate(new Date(), defaultFormat);
	}

	public static String formatDate(Date date) {
		return formatDate(date, defaultFormat);
	}

	/**
	 * 默认日期格式 当前日期
	 * 
	 * @return
	 */
	public static String formatDate(Date date, String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}
	
	public static String transfer2DateString(Timestamp timestamp, String pattern) {
		Date date = new Date(timestamp.getTime());
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(date);
	}
}
